﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BicycleTrafficSimulator.DataModel
{
    class SignDetectingController
    {
        private bool hasStopped;

        private bool isCorrect;

        public bool IsCorrect
        {
            get { return isCorrect; }
            set { isCorrect = value; }
        }

        public SignDetectingController()
        {
            this.hasStopped = false;
            this.isCorrect = false;
        }

        public int DetectSign(string signName, float moveSpeed)
        {
            switch (signName)
            {
                case "stop":
                    return this.DetectStop(moveSpeed);
                case "priorityRoadSign":
                    return this.DetectPriorityRoadSign(moveSpeed);                
                case "prioritySign":
                    return this.DetectPrioritySign(moveSpeed);
                case "yieldSign":
                    return this.DetectYieldSign(moveSpeed);                  
                default: return -1;
            }

        }

        private int DetectYieldSign(float moveSpeed)
        {
            if (moveSpeed == 0.0f)
            {
                this.hasStopped = true;
                this.isCorrect = true;
                return 0;
            }
            return 2; 
        }

        private int DetectPrioritySign(float moveSpeed)
        {
            if (moveSpeed == 0.0f)
            {
                this.hasStopped = true;

            }
            else if ((moveSpeed != 0.0f) && (hasStopped == true))
            {
                this.isCorrect = false;
                return 3;
            }
            this.isCorrect = true;
            return -1;
           
        }

        private int DetectPriorityRoadSign(float moveSpeed)
        {
            if (moveSpeed == 0.0f)
            {
                this.hasStopped = true;

            }
            else if ((moveSpeed != 0.0f) && (hasStopped == true))
            {
                this.isCorrect = false;
                return 4;
            }
            this.isCorrect = true;
            return -1;
        }

        private int DetectStop(float moveSpeed)
        { 
                if (moveSpeed == 0.0f)
                {

                    this.hasStopped = true;
                    this.isCorrect = true;
                    return 0;
                }
        return 1;                     
        }

        public void resetValues()
        {
            this.hasStopped = false;
            this.isCorrect = false;
        }
    }
}
